package cn.yunhe.insurance.service.impl;


import cn.yunhe.insurance.dao.CheckDao;
import cn.yunhe.insurance.entity.Branch;
import cn.yunhe.insurance.entity.Case;
import cn.yunhe.insurance.entity.Order;
import cn.yunhe.insurance.service.CheckService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author李仕龙
 */
@Service("checkService")
public class CheckServiceImpl implements CheckService {

    @Resource
    private CheckDao checkDao;
    @Override
    public Page queryLikeCase(Map<String, Object> cond) {
        Page page=new Page();

        //获取每页大小
        int pageSize=Integer.parseInt(String.valueOf(cond.get("pageSize")));

        //获取当前页码
        int currPageNum=Integer.parseInt(String.valueOf(cond.get("pageNum")));

        //得到记录总数，返回给page的total属性
        page.setTotal(checkDao.getLikeCaseCount(cond));

        //启用分页
        page=PageHelper.startPage(currPageNum,pageSize);

        //得到查询列表
        List list=checkDao.getLikeCase(cond);
        return page;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT,timeout=36000,rollbackFor=Exception.class)
    public Boolean changeCaseState(Case c) {
        return checkDao.changeCaseState(c);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT,timeout=36000,rollbackFor=Exception.class)
    public Boolean changeBranchState(Branch branch) {
        return checkDao.changeBranchState(branch);
    }

    @Override
    public Page<Order> getBackOrder(Map<String, Object> cond) {
        Page page=new Page();

        //获取每页大小
        int pageSize=Integer.parseInt(String.valueOf(cond.get("pageSize")));

        //获取当前页码
        int currPageNum=Integer.parseInt(String.valueOf(cond.get("pageNum")));

        //得到记录总数，返回给page的total属性
        page.setTotal(checkDao.getBackOrderCount(cond));

        //启用分页
        page=PageHelper.startPage(currPageNum,pageSize);

        //得到查询列表
        List<Order> list=checkDao.getBackOrder(cond);
        return page;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT,timeout=36000,rollbackFor=Exception.class)
    public Boolean changeOrderState(Order order) {
        return checkDao.changeOrderState(order);
    }


    public CheckDao getCheckDao() {
        return checkDao;
    }

    public void setCheckDao(CheckDao checkDao) {
        this.checkDao = checkDao;
    }
}
